package br.org.etec.dotcao.service.jpa;

import java.util.List;

import br.org.etec.dotcao.model.Repository;
import br.org.etec.dotcao.model.RepositoryFactory;
import br.org.etec.dotcao.service.Service;

public class ServiceImpl<T> implements Service<T> {

	private Repository<T> repository;
	private Class<T> type;
	
	public ServiceImpl(Class<T> type) {
		super();
		this.type = type;
	}
	
	protected Repository<T> repository() {
		if(repository == null){
			repository = RepositoryFactory.get(type);
		}
		
		return repository;
	}
	
	@Override
	public T get(Long id) {
		return repository().get(id);
	}

	@Override
	public List<T> all() {
		return repository().all();
	}


	
}
